from django.contrib import admin
from .models import MusicComposition, AudioSynthesis


@admin.register(MusicComposition)
class MusicCompositionAdmin(admin.ModelAdmin):
    list_display = ['title', 'user', 'style', 'status', 'created_at']
    list_filter = ['status', 'style', 'created_at']
    search_fields = ['title', 'description']


@admin.register(AudioSynthesis)
class AudioSynthesisAdmin(admin.ModelAdmin):
    list_display = ['text_preview', 'user', 'voice_type', 'status', 'file_size', 'created_at']
    list_filter = ['status', 'voice_type', 'created_at']
    search_fields = ['text_content']
    readonly_fields = ['file_size', 'duration', 'created_at', 'updated_at']
    
    def text_preview(self, obj):
        """文本预览"""
        return obj.text_content[:50] + '...' if len(obj.text_content) > 50 else obj.text_content
    text_preview.short_description = '文本预览'
